package top.lixunda.ecommerce.server.good.api.entity.vo;

import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.experimental.Accessors;
import org.springframework.beans.BeanUtils;
import top.lixunda.ecommerce.server.good.api.entity.db.SysGoodCategoryDO;

import java.util.List;
import java.util.Objects;
import java.util.stream.Collectors;

/**
 * 普通类型的商品目录
 *
 * @author Xumda
 * @version time:2020/1/11 10:56
 */
@SuppressWarnings("WeakerAccess")
@Data
@EqualsAndHashCode(callSuper = false)
@Accessors(chain = true)
public class SysGoodCategoryVO {

    /**
     * 唯一id
     */
    private Integer id;

    /**
     * 商品类别名称
     */
    private String name;

    /**
     * 描述
     */
    private String description;

    /**
     * 是否叶节点 1 是 0 不是
     */
    private Integer isLeaf;

    /**
     * 是否根节点 1 是 0 不是
     */
    private Integer isRoot;

    /**
     * 父节点
     */
    private Integer parentId;

    /**
     * 转换
     */
    public static SysGoodCategoryVO fromGoodCategoryDO(SysGoodCategoryDO sysGoodCategoryDO) {
        if (sysGoodCategoryDO == null) {
            return null;
        }
        SysGoodCategoryVO vo = new SysGoodCategoryVO();
        BeanUtils.copyProperties(sysGoodCategoryDO, vo);
        return vo;
    }

    /**
     * 转换
     */
    public static List<SysGoodCategoryVO> fromGoodCategoryDO(List<SysGoodCategoryDO> list) {
        if (list == null) {
            return null;
        }
        return list.stream()
                .map(SysGoodCategoryVO::fromGoodCategoryDO)
                .filter(Objects::nonNull)
                .collect(Collectors.toList());
    }

}
